package com.totoro.boot.swagger.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * Created by Niki on 2018/7/4 21:02
 */
@RestController
public class UserInfoController {



    @GetMapping (value = "/users")
    public List<String> findAll() {

        return Arrays.asList("1", "2");
    }

    @GetMapping(value = "/user/{name}/{age}")
    public String findUserByNameAndAge(String name, Integer age) {
        return "根据姓名和年龄获取用户信息";
    }

    @PostMapping(value = "/address")
    public String findAddress(@RequestBody String data) {
       JSONObject jsonData = JSONObject.parseObject(data);
        String name = jsonData.getString("name");
        int age = jsonData.getInteger("age");
        return String.format("根据姓名:%s和年龄:%d获取用户信息",name, age);
    }
}
